package com.ruoyi.zhgd.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhgd.domain.TCustomReport;
import com.ruoyi.zhgd.service.CustomReportService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 自定义报表
 * @Author zky
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/customReport")
public class CustomReportController extends BaseController {

    @Autowired
    private CustomReportService customReportService;

    /**
     * 保存
     * @param customReport
     * @return
     */
    @Log(title = "保存自定义报表", businessType = BusinessType.INSERT)
    @SaCheckLogin
    @PostMapping("/insertCustomReport")
    public R insertCustomReport(@RequestBody TCustomReport customReport) {
        return R.ok(customReportService.insertCustomReport(customReport));
    }

    /**
     * 发布/撤销
     * @param customReport
     * @return
     */
    @Log(title = "发布自定义报表", businessType = BusinessType.UPDATE)
    @SaCheckLogin
    @PostMapping("/updateCustomReport")
    public R updateCustomReport(@RequestBody TCustomReport customReport) {
        return toAjax(customReportService.updateCustomReport(customReport));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @Log(title = "删除自定义报表", businessType = BusinessType.DELETE)
    @SaCheckLogin
    @PostMapping("/deleteCustomReport")
    public R deleteCustomReport(@RequestBody Long[] ids) {
        return toAjax(customReportService.deleteCustomReport(ids));
    }

    /**
     * 查询/适用
     * @param customReport
     * @return
     */
    @SaCheckLogin
    @GetMapping("/selectCustomReportPageLike")
    public TableDataInfo<TCustomReport> selectCustomReportPageLike(TCustomReport customReport, PageQuery pageQuery) {
//        startPage();
        Page<TCustomReport> tCustomReportList = customReportService.selectCustomReportPageLike(pageQuery, customReport);
        return TableDataInfo.build(tCustomReportList);
    }

    /**
     * 根据id查询详情
     * 状态 1：草稿 2：发布
     * @param ids
     * @param status
     * @return
     */
    @SaCheckLogin
    @PostMapping("/selectCustomReportByIds")
    public R selectCustomReportByIds(@RequestBody Long[] ids, @RequestParam(value = "status", required = false) Integer status) {
        return R.ok(customReportService.selectCustomReportByIds(ids, status));
    }
}
